package communication;

public class Queue {
	
	private int[] data;
	private int currentIndex = 0;
	private boolean wrappedAround;
	
	public Queue(int size)
	{
		data = new int[size];
	}
	
	public void add(int value)
	{
		if(currentIndex == data.length){
			currentIndex=0;
			wrappedAround=true;
		}
		
		data[currentIndex] = value;
		currentIndex++;
	}
	
	public int get(int index)
	{	
		if(wrappedAround)
		{
			return data[(currentIndex + index)%data.length];
		}
		else
		{
			return data[index];
		}
	}
	
	public int size()
	{
		if(!wrappedAround)
			return currentIndex;
		return data.length;
	}
	
	public void clear()
	{
		for(int i=0; i<data.length; i++)
		{
			data[i]=0;
		}
	}
	
	

}